package suncertify.db.test;

import suncertify.contractors.Contractor;
import suncertify.db.Data;
import suncertify.remoting.RemoteContractorsAccessImpl;

public class FindByCriteriaUser extends Thread {

    private Data data;
    private long[] records;
    private int iteration;
    private String[] criteria;

    public FindByCriteriaUser(String name, Data data, int iterationCount, String[] criteria) {

	super.setName(name);
	this.data = data;
	this.iteration = iterationCount;
	this.criteria = criteria;
    }

    public void run() {

	long[] result;

	for (int i = 1; i <= this.iteration; ++i) {

	    // Data.log("", "===== FindByCriteriaUser iteration  " + Integer.toString(i) + " =====");

	    try {

		result = this.data.findByCriteria(criteria);

		// Data.log("", "===== FindByCriteriaUser criteria = " + " result count =  "
		// + Integer.toString(result.length) + " ==================");

	    } catch (Exception e) {
		e.printStackTrace();
	    }
	}
    }
}

class FindByCriteriaUser2 extends Thread {

    private RemoteContractorsAccessImpl data;
    private long[] records;
    private int iteration;
    private String[] criteria;

    public FindByCriteriaUser2(String name, RemoteContractorsAccessImpl data, int iterationCount, String[] criteria) {

	super.setName(name);
	this.data = data;
	this.iteration = iterationCount;
	this.criteria = criteria;
    }

    public void run() {

	Contractor[] result;

	for (int i = 1; i <= this.iteration; ++i) {

	    // Data.log("", "===== FindByCriteriaUser iteration  " + Integer.toString(i) + " =====");

	    try {

		result = this.data.findByCriteria(criteria);

		// Data.log("", "===== FindByCriteriaUser criteria = " + " result count =  "
		// + Integer.toString(result.length) + " ==================");

	    } catch (Exception e) {
		e.printStackTrace();
	    }
	}
    }
}

class FindByCriteria3 extends Thread {

    private String userName;
    private String serverName;
    private int portNumber;
    private int iterations;

    public FindByCriteria3(String name, String serverName, int portNumber, int iterations) {

	super.setName(name);
	this.serverName = serverName;
	this.portNumber = portNumber;
	this.userName = name;
	this.iterations = iterations;
    }

    public void run() {

	// String[] fields;
	// Contractor[] findResult;
	//
	// RemoteContractorsAccess access;
	// try {
	// access = RmiClient.getContractorsAccess(this.serverName, this.portNumber);
	// } catch (ServerClientException e1) {
	// // Data.log("", "ServerClientException");
	// return;
	// }
	//
	// for (int i = 1; i <= this.iterations; ++i) {
	//
	// // Data.log("", "================= FindByCriteriaUser3 user iteration " + Integer.toString(i)
	// // + " ==================");
	//
	// try {
	// findResult = access.findByCriteria(new String[] { "dogs", null, null, null, null, null });
	// // Data.log("", "findResult=" + Integer.toString(findResult.length));
	// } catch (IllegalStateException e) {
	// // Data
	// // .log("",
	// //
	// "FindByCriteriaUser3. updateContractor threw IllegalStateException!! will exit no unlock is necessary the client!!!");
	// } catch (Exception e) {
	// // Data.log("", "FindByCriteriaUser3. updateContractor threw Exception!!");
	// }
	// }
    }
}